package camp.android.cookbook;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class RecipeView extends Activity
{
	private Recipe recipe;
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		recipe = (Recipe) getIntent().getSerializableExtra("recipe");
		setContentView(R.layout.recipe_view);
		//String title = recipe.getTitle();
		//String subtitle = recipe.getSubtitle();
		//String ingredientText = recipe.getIngredients();
		//String procedureText = recipe.getProcedure();
		((TextView)findViewById(R.id.title)).setText(recipe.getTitle());
		((TextView)findViewById(R.id.subtitle)).setText(recipe.getSubtitle());
		((TextView)findViewById(R.id.ingredients)).setText(recipe.getIngredients());
		((TextView)findViewById(R.id.procedure)).setText(recipe.getProcedure());
		((TextView)findViewById(R.id.notes)).setText(recipe.getNotes());
		
		Button edit_ingredients = (Button)findViewById(R.id.edit_ingredients);
		edit_ingredients.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{	
				Intent i = new Intent(getApplicationContext(), NewRecipe.class);
				i.putExtra("recipe", recipe);
				startActivity(i);
			}
			
		});
		
		Button edit_procedure = (Button)findViewById(R.id.edit_procedure);
		edit_procedure.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{	
				Intent i = new Intent(getApplicationContext(), NewProcedure.class);
				i.putExtra("recipe", recipe);
				startActivity(i);
			}
			
		});
		
		Button edit_notes = (Button)findViewById(R.id.edit_notes);
		edit_notes.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{	
				Intent i = new Intent(getApplicationContext(), NewProcedure.class);
				i.putExtra("recipe", recipe);
				startActivity(i);
			}
			
		});
	}
	
	
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    switch (item.getItemId()) {
	        case android.R.id.home:
	            // app icon in Action Bar clicked; go home
	            Intent intent = new Intent(this, RecipeListView.class);
	            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	            startActivity(intent);
	            return true;
	        default:
	            return super.onOptionsItemSelected(item);
	    }
	}
}